package net.stuffrepos.bricknetcenter.database;

import java.util.LinkedList;
import java.util.List;
import net.stuffrepos.bricknetcenter.database.schema.Information;
import net.stuffrepos.bricknetcenter.database.schema.Information.Type;
import org.apache.commons.lang.StringUtils;

/**
 *
 * @author Eduardo H. Bogoni <eduardobogoni@gmail.com>
 */
public class InformationTree {

    private List<InformationTree> children = new LinkedList<InformationTree>();
    private final Type rootType;
    private final String rootValue;

    public InformationTree() {
        this(null, null);
    }

    public InformationTree(Information.Type rootType, String rootValue) {
        this.rootType = rootType;
        this.rootValue = rootValue;
    }

    public InformationTree addChild(InformationTree child) {
        children.add(child);
        return child;
    }

    public InformationTree addChild(Information.Type childType, String childValue) {
        return addChild(new InformationTree(childType, childValue));        
    }

    public Type getRootType() {
        return rootType;
    }

    public String getRootValue() {
        return rootValue;
    }

    public Iterable<InformationTree> getChildren() {
        return children;
    }

    public void debug() {
        debug(0);       
    }

    private void debug(int level) {
        System.out.println(StringUtils.repeat("  ", level) + rootType + "=" + rootValue);
        for(InformationTree subTree: children) {
            subTree.debug(level + 1);
        }
    }
}
